Skip to main content

First Agent

In BindAI, an Agent is the core building block of every AI application. An agent connects a language model with instructions, tools, memory, knowledge, and workflows to perform useful tasks. This guide explains how agents work and how to build your own.

What is an Agent?

An agent is responsible for:
  • Receiving user input
  • Building a prompt
  • Sending the request to a language model
  • Executing tools when required
  • Returning the final response
Unlike calling an LLM directly, a BindAI agent can be extended with additional capabilities while keeping the application architecture clean.

Creating an Agent

The simplest agent only requires a provider, model, and instructions.
You can immediately interact with it.

Agent Components

A BindAI agent is composed of several optional building blocks. You can start with only a provider and model, then add more capabilities as your application grows.

System Instructions

Instructions define the agent’s personality and behavior.
Good instructions usually describe:
  • The agent’s role
  • Desired writing style
  • Constraints
  • Expected output format

Sending Messages

Use the chat() method to send a prompt.
The returned value is an AgentResult.
Typical output:

Structured Output

Agents can also return structured data. Suppose you have a Pydantic model.
Pass it as the output argument.
The response becomes an instance of your model instead of plain text.

Loading Agents from YAML

Agents can be defined without writing Python code. Example configuration:
Load it.
YAML is useful for production projects where prompts and models change frequently.

Streaming Responses

Instead of waiting for the complete answer, responses can be streamed token by token.
Streaming is recommended for chat interfaces and long responses.

Agent Lifecycle

Internally, every execution follows the same pipeline.
  1. Receive user input
  2. Build the prompt
  3. Load memory
  4. Retrieve knowledge (if configured)
  5. Send the request to the language model
  6. Execute requested tools
  7. Generate the final response
  8. Save conversation memory
  9. Return an AgentResult
This lifecycle remains the same regardless of whether the agent uses tools, workflows, or retrieval.

Extending an Agent

Agents become more powerful by adding additional capabilities. For example, register a tool.
Attach memory.
Connect knowledge retrieval.
These extensions allow the same agent architecture to support increasingly complex applications.